﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TFXSDGB13
    {
        public TFXSDGB13()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_STOCK();
            this.DataContext = MV;
            InitializeComponent();
            if (app.User.Trim() == "ITXV")
                ART = "40005.NE.50.1";
            LO = "01";
            LB = "XS";
            ART = "4";
            PARTIE = "H";
            DTSTART = MV.date;

        }
        public override void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            base.bgWorker_RunWorkerCompleted(sender, e);
            vwMaster.View.MoveCurrentTo(-1);
            EventDispatcher.Instance.RaiseStatus("完成数据更新", StatusEventType.StopProgress);
        }

        public override void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            base.bgWorker_DoWork(sender, e);
            EventDispatcher.Instance.RaiseStatus("开始更新数据", StatusEventType.RunningProgress);
            TMV.EXEGI09(PM["DTSTART"], "G");

        }
        public void FilterMaster_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string filter = "ART LIKE '%" + ART.Trim() + "%' AND FARBE LIKE '" + FARBE + "%' AND ( SPPART LIKE '%" + DESS.Trim() + "%' OR FBPART LIKE '%" + DESS.Trim() + "%')";
                cvMaster.CustomFilter = filter;
            }
            catch(Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex.Message);
            }
            
        }

        public void FilterMasterClear_Click(object sender, RoutedEventArgs e)
        {

            cvMaster.CustomFilter = null;
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            PM["DTSTART"] = DTSTART;
            bgWorker.RunWorkerAsync();
            Tracer.Info("", "已经更新完成");
            base.NewCommand(sender, e);

        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            IsBusy = true;
            PM["MDATE"] = DTSTART;
            PM["LO"] = LO;
            PM["LB"] = LB;
            PM["ART"] = ART;
            PM["VAR"] = VAR;
            PM["PARIE"] = PARTIE;
            PM["AND"] = " AND BS13>0";
            SResult = TMV.LoadStock(PM);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
            IsBusy = false;
        }
        public override void PrintCommand(object sender, RoutedEventArgs e)
        {
            DataSet Set = new DataSet();
            Set.Merge(TBMain);
            cDR.PRINT(Set);
            base.PrintCommand(sender, e);
        } 
    }
}
